package com.aaa.controller.sds;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.sds.TTestRecondSds;
import com.aaa.service.sds.TTestRecondSdsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * (TTestRecondSds)表控制层
 *
 * @author ZXJ
 * @since 2022-11-07 12:53:46
 */
@RestController
@RequestMapping("tTestRecondSds")
public class TTestRecondSdsController {
    /**
     * 服务对象
     */
    @Autowired
    private TTestRecondSdsService tTestRecondSdsService;

    /**
     * 分页查询所有
     * @param myPage
     * @param tTestRecondSds
     * @return
     */
    @GetMapping("/selectall")
    public LayData selectall(MyPage myPage, TTestRecondSds tTestRecondSds){
        PageInfo selectall = tTestRecondSdsService.selectall(myPage, tTestRecondSds);
        System.out.println("回访selectall = " + selectall);
        return  new LayData(tTestRecondSdsService.selectall(myPage,tTestRecondSds));
    }

    @PostMapping("del")
    @ResponseBody
    /**
     * 根据id删除
     */
    public LayData delete(Integer id){
        return new LayData( tTestRecondSdsService.delete(id));
    }


    /**
     * 修改
     * @param tTestRecondSds
     * @param session
     * @return
     */

    @PostMapping ("/update")
    public LayData update(TTestRecondSds tTestRecondSds, HttpSession session){
        User user = (User) session.getAttribute("user");
        tTestRecondSds.setUpdateby(user.getUsername());
        return new LayData(tTestRecondSdsService.update(tTestRecondSds));
    }

    /**
     *添加到回访
     * @param request
     * @param session
     * @return
     */
    @PostMapping("/add")
    private LayData add(HttpServletRequest request, HttpSession session,TTestRecondSds tTestRecondSds){
        String username = request.getParameter("username");
        System.out.println("11111username = " + username);
        Integer id = tTestRecondSdsService.selectidByusername(username);
        System.out.println("id = " + id);
        Integer rid = tTestRecondSdsService.selectusernameidByusername(id);
        System.out.println("rid = " + rid);
        if (rid>0){
            System.out.println("11111111111111");
            return new LayData(false);
        }
        return new LayData(tTestRecondSdsService.add(request,session,tTestRecondSds));
    }

}

